import {create} from 'zustand'
import {IThemeDate, MapData} from "../types";

interface AppState {
    // Data
    testData: string;
    spinning:boolean,
    mapData:MapData,
    currentMode:string,
    currentTopicWord:string,
    themeDateData:IThemeDate[],
    topicHeat:MapData,
    allTopicWord:MapData,
    topicWord:MapData,
    // Actions
    setTestData: (data: string) => void;
    setSpinning: (spinning: boolean) => void;
    setMapData: (data: MapData) =>void,
    setTopicHeat:(data:MapData)=>void,
    setAllTopicWord:(data:MapData)=>void,
    setTopicWord:(data:MapData)=>void,
    setCurrentMode:(data:string) =>void,
    setCurrentTopicWord:(data:string)=>void,
    setThemeDateData:(data:IThemeDate[])=>void,
    //获取最新的store
    getState: () => AppState;
}

const useAppState = create<AppState>((set, get) => ({
    testData: '',
    spinning: true,
    mapData: {},
    topicHeat:{},
    allTopicWord:{},
    topicWord:{},
    themeDateData:[],
    currentMode:"Representative_Docs_gps",
    currentTopicWord:'',
    setSpinning: (spinning) => set({spinning: spinning}),
    setMapData: (data) => set({mapData: data}),
    setTopicHeat:(data) => set({topicHeat:data}),
    setAllTopicWord:(data)=>set({allTopicWord:data}),
    setTopicWord:(data)=>set({topicWord:data}),
    setTestData: (data) => set({testData: data}),
    setCurrentMode:(data:string)=>set({currentMode:data}),
    setCurrentTopicWord:(data:string)=>set({currentTopicWord:data}),
    setThemeDateData:(data:IThemeDate[])=>set({themeDateData:data}),
    getState:()=>get()
}))

export default useAppState;
